<?php 
class Model_News_Tag extends ypModel {
	private $_postId;
	public function loadPost($tag) {
		$result = $this->Db->query("SELECT `post_id` FROM `yp_module_news_tag`
		WHERE `tag` = '". $this->Db->e($tag) ."'");
		
		if ($this->Db->num_rows() == 0) {
			return array();
		}
		
		$posts = array();
		while ($row = $this->Db->fetch($result)) {
			if ($this->_postId[$row['post_id']]) continue;
			$this->_postId[$row['post_id']] = true;
			$post = $this->getPost($row['post_id']);
			$post['post'] = htmlspecialchars_decode($post['post']);
			
			$posts[] = $post;
		}
		
		return $posts;
	}

	public function getPost($id) {
		$this->Db->query("SELECT * FROM `yp_module_news` 
		WHERE `post_id` = " . (int) $id);
		if ($this->Db->num_rows() == 0) {
			return array();
		}
		
		return $this->Db->fetch();
	}
}